#coding: utf-8
from django.db import models
from django.contrib.auth.models import User
from taxonomy.models import Category, Tag


class Resource( models.Model ):
    TYPE_CHOICES = (
        ( '1', 'Article' ),
        ( '2', 'Image' ),
        ( '3', 'Video' ),
        ( '4', 'Text' ),
    )
    type = models.CharField( max_length = 1, choices = TYPE_CHOICES, verbose_name = '类型' )
    title = models.CharField( max_length = 100, verbose_name = '标题' )
    content = models.TextField( blank = True, null = True, verbose_name = '内容' )
    url = models.URLField( blank = True, null = True, unique = True, verbose_name = 'URL' )
    description = models.TextField( blank = True, null = True, verbose_name = '描述' )
    digg = models.IntegerField( default = 0, verbose_name = 'digg' )
    categories = models.ManyToManyField( Category, verbose_name = '分类' )
    tags = models.ManyToManyField( Tag, verbose_name = '标签' )
    
    def __unicode__( self ):
        return self.title


class ResourceComment( models.Model ):
    user = models.ForeignKey( User, verbose_name = 'posted_by' )
    post_time = models.DateTimeField()
    content = models.TextField()
    resource = models.ForeignKey( Resource )

